package com.zhoujing.cinema.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhoujing.cinema.dao.MovieDao;
import com.zhoujing.cinema.entity.*;
import com.zhoujing.cinema.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ：ywj
 * @date ：Created in 2020/3/18 14:35
 * @description：
 * @modified By：
 * @version: $
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
public class MovieServiceImpl implements MovieService {
    @Autowired
    public MovieDao movieDao;
    @Override
    public Movie findMovieById(Integer id) {
        return movieDao.selectMovieById(id);
    }

    @Override
    public PageInfo<Comment> findCommentByMovieId(Integer id,Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Comment> comments= movieDao.selectCommentByMovieId(id);
        PageInfo<Comment> pageInfo = new PageInfo<>(comments);
        return pageInfo;
    }

    @Override
    public void insertWish(Wish wish) {
        movieDao.insertWish(wish);
    }

    @Override
    public void updateMovieWish(Movie movie) {
        movieDao.updateMovieWish(movie);
    }

    @Override
    public Wish selectWish(Integer id) {
        return movieDao.selectWish(id);
    }

    @Override
    public Comment selectComment(Integer id) {
        return movieDao.selectComment(id);
    }

    @Override
    public void insertComment(CommentDto comment) {
        movieDao.insertComment(comment);
    }

    @Override
    public List<Comment> selectCommentByMovie(Integer id) {
        return movieDao.selectCommentByMovie(id);
    }

    @Override
    public void updateMovieScore(Movie movie) {
        movieDao.updateMovieScore(movie);
    }

    @Override
    public List<Banner> selectBanner() {
        return movieDao.selectBanner();
    }

    @Override
    public List<Movie> findType1Eight() {
        return movieDao.selectType1Eight();
    }

    @Override
    public List<Movie> findType1Ten() {
        return movieDao.selectType1Ten();
    }

    @Override
    public List<Movie> findType2Eight() {
        return movieDao.selectType2Eight();
    }

    @Override
    public List<Movie> findType2Ten() {
        return movieDao.selectType2Ten();
    }

    @Override
    public List<Movie> findType3Eight() {
        return movieDao.selectType3Eight();
    }

    @Override
    public List<Movie> findType3Ten() {
        return movieDao.selectType3Ten();
    }

    @Override
    public PageInfo<Movie> findMovieSearch(String name, Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectMovieSearch(name);
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public List<Type> findType() {
        return movieDao.selectType();
    }

    @Override
    public List<Year> findYear() {
        return movieDao.selectYear();
    }

    @Override
    public List<Country> findCountry() {
        return movieDao.selectCountry();
    }

    @Override
    public PageInfo<Movie> findMovieType1(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectMovieType1();
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public PageInfo<Movie> findMovieType2(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectMovieType2();
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public PageInfo<Movie> findMovieType3(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectMovieType3();
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public PageInfo<Movie> selectMovieWithQuery1(MovieDto movieDto, Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectMovieWithQuery1(movieDto);
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public PageInfo<Movie> selectMovieWithQuery2(MovieDto movieDto, Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectMovieWithQuery2(movieDto);
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public PageInfo<Movie> selectMovieWithQuery3(MovieDto movieDto, Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectMovieWithQuery3(movieDto);
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public void insertMovie(Movie movie) {
        movieDao.insertMovie(movie);
    }

    @Override
    public PageInfo<Movie> selectAllMovie(Integer pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Movie> movies= movieDao.selectAllMovie();
        PageInfo<Movie> pageInfo = new PageInfo<>(movies);
        return pageInfo;
    }

    @Override
    public Movie selectMovieByIds(Integer id) {
        return movieDao.selectMovieByIds(id);
    }

    @Override
    public void updateMovie(Movie movie) {
        movieDao.updateMovie(movie);
    }

    @Override
    public List<Movie> selectType1() {
        return movieDao.selectType1();
    }

}
